From 3921297ea29b8f5b2da00e4b6f266d899b158f41 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Fri, 14 May 2010 07:53:16 +0100 Subject: [PATCH] libxl: Adjustments to memset/memmax handling I think xl memset should change the memory currently used by the guest and xl memmax should change the size of the guest's address space and not the population. For this reason libxl_set_memory_target should provide a way to enforce the memory target, calling xc_domain_setmaxmem. On the other hand xl memmax shouldn't call xc_domain_setmaxmem because that is the upper bound of the memory reservation, it should just change static-max, that at the moment wouldn't do much, but we can imagine that in the future could trigger something useful in the guest. Signed-off-by: Stefano Stabellini Acked-by: Jonathan Knowles =20 --- tools/libxl/libxl.c | 16 ++++++++-------- tools/libxl/libxl.h | 2 +- tools/libxl/xl_cmdimpl.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 967f804037..c00e08fe2d 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2468,7 +2468,6 @@ int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t max_m char *mem, *endptr; uint32_t memorykb; char *dompath = libxl_xs_get_dompath(ctx, domid); - int rc; mem = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/memory/target", dompath)); if (!mem) { @@ -2486,20 +2485,16 @@ int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t max_m return 1; } - rc = xc_domain_setmaxmem(ctx->xch, domid, max_memkb); - if (rc != 0) - return rc; - if (domid != 0) libxl_xs_write(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/memory/static-max", dompath), "%lu", max_memkb); - return rc; + return 0; } -int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb) +int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce) { int rc = 0; - uint32_t memorykb, videoram; + uint32_t memorykb = 0, videoram = 0; char *memmax, *endptr, *videoram_s = NULL; char *dompath = libxl_xs_get_dompath(ctx, domid); xc_domaininfo_t info; @@ -2539,6 +2534,11 @@ int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t targ uuid = libxl_uuid2string(ctx, ptr.uuid); libxl_xs_write(ctx, XBT_NULL, libxl_sprintf(ctx, "/vm/%s/memory", uuid), "%lu", target_memkb / 1024); + if (enforce || !domid) + memorykb = target_memkb; + rc = xc_domain_setmaxmem(ctx->xch, domid, memorykb + LIBXL_MAXMEM_CONSTANT); + if (rc != 0) + return rc; rc = xc_domain_memory_set_pod_target(ctx->xch, domid, (target_memkb - videoram) / 4, NULL, NULL, NULL); return rc; } diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 130af2442d..e951111fcf 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -340,7 +340,7 @@ int libxl_domain_pause(struct libxl_ctx *ctx, uint32_t domid); int libxl_domain_unpause(struct libxl_ctx *ctx, uint32_t domid); int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb); -int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb); +int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce); int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num); diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index aa07996510..2101ee58d0 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1262,7 +1262,7 @@ void set_memory_target(char *p, char *mem) exit(3); } printf("setting domid %d memory to : %d\n", domid, memorykb); - libxl_set_memory_target(&ctx, domid, memorykb); + libxl_set_memory_target(&ctx, domid, memorykb, /* enforce */ 1); } int main_memset(int argc, char **argv) -- 2.30.2